﻿@model IEnumerable<FollowPeers.Models.Group>
@{
    ViewBag.Title = "Search Results";
    @Html.Partial("_Header")
    FollowPeers.Models.FollowPeersDBEntities followPeersDB = new FollowPeers.Models.FollowPeersDBEntities();
    var keywords = ViewData["keywords"];
    @Html.Partial("_SideBar1")   
}
<div class="grid_10">
    <div class="box">
        <h2>
            <select style="margin-left: 200px" onchange="return setswitch(this);">
            </select>
            <div class="editing" style="float: right">
                <span id="trigger" style="line-height: 22px; float: right; text-decoration: underline;
                    cursor: pointer;">Advanced Search</span>
                <div id="toolWrapper" style="display: none; top: -7px;">
                    <div style="padding: 7px; color: #777; background: #ddd; width: 100%; margin: 3px;">
                        Advanced Group Search</div>
                    <form style="padding: 7px;">
                    <div class="editor-label" style="color: grey; font-weight: bold;">
                        Keywords</div>
                    <input type="hidden" name="sort" value="1" />
                    <div class="editor-field" style="height: auto">
                        <input type="text" name="keywords" value="@keywords" style="width:252px;" />
                    </div>
                    
                    <div class="editor-field" style="height: auto">
                        @{
                            List<SelectListItem> items = new List<SelectListItem>();
                            foreach (var i in followPeersDB.Groups)
                            {
                                items.Add(new SelectListItem { Text = i.Name, Value = i.Name });
                            }
                            IEnumerable<SelectListItem> list = items.ToArray();
                            @Html.DropDownList("Country", list, new { style = "width:257px;" });
                             
                        }
                    </div>
                                        
                    <input type="submit" style="float: right; padding: 5px; background: #ccc; cursor: pointer;
                        margin-top: -10px; margin-right: 1px; border: 1px solid #bbb;" value="Submit" />
                    </form>
                </div>
            </div>
        </h2>
        @if (Model.Count() == 0)
        {
            <div style="padding: 10px;">
                No Results Found</div>
        }
        else
        {
            IEnumerable<FollowPeers.Models.Group> listtosort = null;
            if (ViewBag.sort == 1)
            {
                listtosort = Model.OrderByDescending(x => x.Name);
            }
            else
            {
                listtosort = Model.OrderByDescending(x => x.Members.Count());
            }

            foreach (var item in listtosort)
            {   <div style="height: 90px">
                @{
                FollowPeers.Models.UserProfile me = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserProfileId == item.OwnerId);
                string myname = Membership.GetUser().UserName;
                FollowPeers.Models.UserProfile myprofile = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == myname);
                }
                @*
                <div class="block" style="overflow: hidden; height: 70px; width: 70px; float: left;
                    text-align: center">
                    <a href="#" /Profile/DetailJob/@item.JobId">
                        <img src="@Html.Encode(me.PhotoUrl)" style="margin-left:auto; margin-right:auto; width:70px;" /></a>
                </div>
                <div style="float: left; margin: 7px 0px 0px 5px;">
                    @Html.ActionLink(item.Title, "DetailJob", new { id = item.JobId }) (@Html.DisplayFor(modelitem => item.Country))
                    <br />
                    Posted By
                    @if (Membership.GetUser().UserName == me.UserName)
                    {
                        @Html.ActionLink("Me", "Index", new { id = me.UserProfileId }) 
                    }
                    else
                    {
                        @Html.ActionLink(me.FirstName + " " + me.LastName, "Index", new { id = me.UserProfileId }) 
                    }
                    on @item.publishDate.ToShortDateString()
                    <br />
                   
                    <br />
                    @{int peoplebookmarked = @item.UserProfile.Count() - 1;}
                    Bookmarked by @peoplebookmarked people
                </div>
                <div id="follow" style="float: right; margin: 15px;">
                    @if (myprofile.UserProfileId != item.ownerID)
                    {

                        if (ViewData[item.JobId.ToString()] == "1")
                        {
                            using (Html.BeginForm("UnBookmark", "Profile", new { url = HttpContext.Current.Request.Url.AbsoluteUri }))
                            {
                        <input type="hidden" name="jobid" value="@item.JobId" />
                        <input type="submit" value="UnBookmark" style="padding: 8px 20px; color: gray; float: right;
                            cursor: pointer; font-weight: bold;" />
                            }
                        }
                        else
                        {
                            using (Html.BeginForm("Bookmark", "Profile", new { url = HttpContext.Current.Request.Url.AbsoluteUri }))
                            {
                        <input type="hidden" name="jobid" value="@item.JobId" />
                        <input type="submit" value="Bookmark" style="padding: 8px 20px; float: right; cursor: pointer;
                            font-weight: bold;" />
                            }
                        }
                    }</div>
                <div style="clear: none">
                </div>
                *@
            </div>
                
                

            }
        }
    </div>
</div>
<div class="grid_3">
    <div class="box">
    </div>
</div>
@Html.Partial("_Footer")
<script type="text/javascript">
    $(document).ready(function () {

        $("#trigger").click(function () {
            $('#toolWrapper').toggle(function () {
                $(document).click(function (event) {
                    if (!($(event.target).is('#toolWrapper') || $(event.target).parents('#toolWrapper').length || $(event.target).is('#trigger'))) {
                        $('#toolWrapper').hide(500);
                    }
                });
            });
        });



    });

    function setswitch(sel) {
        var opt = sel.options[sel.selectedIndex].value;
        if (opt == 1) {
            var location = document.URL.replace("sort=2", "sort=1");
            window.location = location;
        }
        else if (opt == 2) {
            var location = document.URL.replace("sort=1", "sort=2");
            window.location = location;
        }
    }


</script>

